/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[欢迎加盟知启蒙，一起邂逅框架梦]
 * 
 * https://www.zhiqim.com/gitcan/zhiqim/zhiqim_account.htm
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zhiqim.account;

import org.zhiqim.account.cache.SensitiveWordCache;
import org.zhiqim.account.dbo.sys.ZacPayment;
import org.zhiqim.httpd.context.ZmlBootstrap;
import org.zhiqim.httpd.context.core.Context;
import org.zhiqim.kernel.Global;
import org.zhiqim.manager.dao.ZmrParamDao;
import org.zhiqim.orm.ZTable;

/**
 * 知启蒙账户组件引导类
 *
 * @version v1.4.1 @author zouzhigang 2018-4-20 新建与整理
 */
public class ZacBootstrap extends ZmlBootstrap implements ZacConstants
{
    /** 初始化 */
    public void init(Context context) throws Exception
    {
        initParam(context);
        initPayment(context);
        
        // 加载敏感词缓存
        Global.put(SensitiveWordCache.class, new SensitiveWordCache().doRefresh());
    }
    
    /** 初始化参数 */
    private void initParam(Context context) throws Exception
    {
        //QQ互联
        ZmrParamDao.addParam(ZAC_NAME, QQ_APP_ID,        1, "QQ互联中应用的APP ID");
        ZmrParamDao.addParam(ZAC_NAME, QQ_APP_SECRET,    2, "QQ互联中应用的APP KEY");
        ZmrParamDao.addParam(ZAC_NAME, QQ_CALLBACK,      3, "QQ互联中应用的网站回调域对应的URL");
        
        //微信开放平台
        ZmrParamDao.addParam(ZAC_NAME, WXOP_APP_ID,      4, "微信开放平台中应用的AppID");
        ZmrParamDao.addParam(ZAC_NAME, WXOP_APP_SECRET,  5, "微信开放平台中应用的AppSecret");
        ZmrParamDao.addParam(ZAC_NAME, WXOP_CALLBACK,    6, "微信开放平台中应用的授权回调域对应的URL");
        
        //微信公众号
        ZmrParamDao.addParam(ZAC_NAME, WXMP_APP_ID,      7, "微信公众号中应用的AppID");
        ZmrParamDao.addParam(ZAC_NAME, WXMP_APP_SECRET,  8, "微信公众号中应用的AppSecret");
        ZmrParamDao.addParam(ZAC_NAME, WXMP_CALLBACK,    9, "微信公众号中应用的授权回调域对应的URL");
        
        //联系客服
        ZmrParamDao.addParam(ZAC_NAME, WXMP_CUSTOMER,    10, "微信公众号中的联系客服链接");
    }
    
    /** 初始化支付表 */
    private void initPayment(Context context) throws Exception
    {
        if (Global.get(ZTable.class).count(ZacPayment.class, "wxpay") == 0)
        {//微信支付
            ZacPayment wxpay = new ZacPayment();
            wxpay.setPaymentCode("wxpay");
            wxpay.setPaymentIco("weixin");
            wxpay.setPaymentName("微信");
            wxpay.setPaymentSeq(100);
            wxpay.setPaymentStatus(0);
            Global.get(ZTable.class).insert(wxpay);
        }
        
        if (Global.get(ZTable.class).count(ZacPayment.class, "alipay") == 0)
        {//支付宝
            ZacPayment alipay = new ZacPayment();
            alipay.setPaymentCode("alipay");
            alipay.setPaymentIco("alipay");
            alipay.setPaymentName("支付宝");
            alipay.setPaymentSeq(110);
            alipay.setPaymentStatus(0);
            Global.get(ZTable.class).insert(alipay);
        }
    }
}
